<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Deliver extends Controller{
  /****
     Class register         查询简历是否投递   
     *@user_id[int]         用户id
     *@moonlighted_id[int]  岗位id
    */
     public function index(){
        $post = input('post.');
        $deliver = Db::name('deliver')->where(['user_id'=>$post['user_id'],'moonlighted_id'=>$post['moonlighted_id']])->find();
        if($deliver){
          $arr = [
            'state'=>1,
            'message'=>'请求成功'
          ];
        }else{
          $arr = [
            'state'=>0,
            'message'=>'请求失败'
          ];
        }
        return json($arr);
     }
    /****
     Class register         投递   
     *@user_id[int]         用户id
     *@moonlighted_id[int]  岗位id
    */
     public function deliver(){
        $post = input('post.');
        $data = [
          'user_id'=>$post['user_id'],
          'moonlighted_id'=>$post['moonlighted_id'],
        ];
        $deliver = Db::name('deliver')->insert($data);
        if($deliver){
          $arr = [
            'state'=>1,
            'message'=>'请求成功'
          ];
        }else{
          $arr = [
            'state'=>0,
            'message'=>'请求失败'
          ];
        }
        return json($arr);
     }
     /****
     Class register         投递记录   
     *@user_id[int]         用户id
     *@moonlighted_id[int]  岗位id
    */
    public function deliver_index(){
        $user_id = input('user_id');
        $deliver = Db::name('deliver a')
              ->where(['a.user_id'=>$user_id])
              ->join('headline_moonlighted b','find_in_set(b.id,a.moonlighted_id)','LEFT')
              ->select();
        if($deliver){
          $arr = [
            'state'=>1,
            'deliver'=>$deliver,
          ];
        }else{
          $arr = [
            'state'=>1,
			'deliver'=>'',
          ];
        }
        return json($arr);
     }
      /****
     Class register         岗位收藏   
     *@user_id[int]         用户id
     *@moonlighted_id[int]  岗位id
    */
     public function post_collection(){
        $post = input('post.');
        $data = [
          'user_id'=>$post['user_id'],
          'moonlighted_id'=>$post['moonlighted_id']
        ];
        $deliver = Db::name('deliver')->insert($data);
        if($deliver){
          $arr = [
            'state'=>1,
            'message'=>'请求成功'
          ];
        }else{
          $arr = [
            'state'=>0,
            'message'=>'请求失败'
          ];
        }
        return json($arr);
     }
     /****
     Class register         岗位收藏详情   
     *@user_id[int]         用户id
     *@moonlighted_id[int]  岗位id
    */
     public function collection_details(){
        $user_id = input('user_id');
        $deliver = Db::name('deliver a')
                  ->where(['a.user_id'=>$user_id])
                  ->join('headline_moonlighted b','find_in_set(b.id,a.moonlighted_id)','LEFT')
                  ->select();
        if($deliver){
          $arr = [
            'state'     =>1,
            'deliver'   =>$deliver,
            'message'   =>'请求成功'
          ];
        }else{
          $arr = [
            'state'     =>1,
            'deliver'   =>'',
            'message'   =>'请求成功'
          ];
        }
        return json($arr);
     }
    
}